package io.unicorn.modules.water.controller;

import java.util.Arrays;
import java.util.Map;

import io.unicorn.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.unicorn.modules.water.entity.TUniinfoWEntity;
import io.unicorn.modules.water.service.TUniinfoWService;
import io.unicorn.common.utils.PageUtils;
import io.unicorn.common.utils.R;



/**
 * ${comments}
 *
 * @author LNCG
 * @email LNCG@USTL.EDU.CN
 * @date 2022-01-18 13:14:05
 */
@RestController
@RequestMapping("water/tuniinfow")
public class TUniinfoWController {
    @Autowired
    private TUniinfoWService tUniinfoWService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("water:tuniinfow:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = tUniinfoWService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{unitId}")
    @RequiresPermissions("water:tuniinfow:info")
    public R info(@PathVariable("unitId") Integer unitId){
        TUniinfoWEntity tUniinfoW = tUniinfoWService.getById(unitId);

        return R.ok().put("tUniinfoW", tUniinfoW);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("water:tuniinfow:save")
    public R save(@RequestBody TUniinfoWEntity tUniinfoW){
        tUniinfoWService.save(tUniinfoW);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("water:tuniinfow:update")
    public R update(@RequestBody TUniinfoWEntity tUniinfoW){
        ValidatorUtils.validateEntity(tUniinfoW);
        tUniinfoWService.updateById(tUniinfoW);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("water:tuniinfow:delete")
    public R delete(@RequestBody Integer[] unitIds){
        tUniinfoWService.removeByIds(Arrays.asList(unitIds));

        return R.ok();
    }

}
